package com.spic.business.riskbase.hierarchy.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.spic.common.core.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.spic.business.riskbase.hierarchy.domain.RiskAnalyse;
import com.spic.business.riskbase.hierarchy.mapper.RiskDescriptionMapper;
import com.spic.business.riskbase.hierarchy.domain.RiskDescription;
import com.spic.business.riskbase.hierarchy.service.IRiskDescriptionService;

/**
 * riskDescriptionService业务层处理
 *
 * @author ruoyi
 * @date 2023-04-14
 */
@Service
public class RiskDescriptionServiceImpl implements IRiskDescriptionService
{
    @Autowired
    private RiskDescriptionMapper riskDescriptionMapper;

    /**
     * 查询riskDescription
     *
     * @param id riskDescription主键
     * @return riskDescription
     */
    @Override
    public RiskDescription selectRiskDescriptionById(Long id)
    {
        return riskDescriptionMapper.selectRiskDescriptionById(id);
    }

    /**
     * 查询riskDescription列表
     *
     * @param riskDescription riskDescription
     * @return riskDescription
     */
    @Override
    public List<RiskDescription> selectRiskDescriptionList(RiskDescription riskDescription)
    {
        return riskDescriptionMapper.selectRiskDescriptionList(riskDescription);
    }

    /**
     * 新增riskDescription
     *
     * @param riskDescription riskDescription
     * @return 结果
     */
    @Transactional
    @Override
    public int insertRiskDescription(RiskDescription riskDescription)
    {
        int rows = riskDescriptionMapper.insertRiskDescription(riskDescription);
        insertRiskAnalyse(riskDescription);
        return rows;
    }

    /**
     * 修改riskDescription
     *
     * @param riskDescription riskDescription
     * @return 结果
     */
    @Transactional
    @Override
    public int updateRiskDescription(RiskDescription riskDescription)
    {
        riskDescriptionMapper.deleteRiskAnalyseByRiskDescriptionId(riskDescription.getId());
        insertRiskAnalyse(riskDescription);
        return riskDescriptionMapper.updateRiskDescription(riskDescription);
    }

    /**
     * 批量删除riskDescription
     *
     * @param ids 需要删除的riskDescription主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteRiskDescriptionByIds(Long[] ids)
    {
        riskDescriptionMapper.deleteRiskAnalyseByRiskDescriptionIds(ids);
        return riskDescriptionMapper.deleteRiskDescriptionByIds(ids);
    }

    /**
     * 删除riskDescription信息
     *
     * @param id riskDescription主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteRiskDescriptionById(Long id)
    {
        riskDescriptionMapper.deleteRiskAnalyseByRiskDescriptionId(id);
        return riskDescriptionMapper.deleteRiskDescriptionById(id);
    }

    @Override
    public int deleteRiskDescriptionByDangerSource(Long id) {
        return riskDescriptionMapper.deleteRiskDescriptionByDangerSource(id);
    }

    @Override
    public int batchRiskDescription(List<RiskDescription> list) {
        return riskDescriptionMapper.batchRiskDescription(list);
    }

    /**
     * 新增${subTable.functionName}信息
     *
     * @param riskDescription riskDescription对象
     */
    public void insertRiskAnalyse(RiskDescription riskDescription)
    {
        List<RiskAnalyse> riskAnalyseList = riskDescription.getRiskAnalyseList();
        Long id = riskDescription.getId();
        if (StringUtils.isNotNull(riskAnalyseList))
        {
            List<RiskAnalyse> list = new ArrayList<RiskAnalyse>();
            for (RiskAnalyse riskAnalyse : riskAnalyseList)
            {
                riskAnalyse.setRiskDescriptionId(id);
                list.add(riskAnalyse);
            }
            if (list.size() > 0)
            {
                riskDescriptionMapper.batchRiskAnalyse(list);
            }
        }
    }
}
